#!/usr/bin/php -q
<?php

	require_once("/var/www/html/web/configs/default.php");
	require_once(lucc_basedir("libs/agi/phpagi.php"));
	lucc_load('msg');

	global $argv;

	$agi = new AGI();

	$caller_id = $agi->get_variable('CALLERID(num)');
	$caller_id = lucc_item($caller_id, 'data');
	if(! $caller_id)
		exit(0);

	$unique_id = $agi->get_variable('UNIQUEID');
	$unique_id = lucc_item($unique_id, 'data');
	if(! $unique_id)
		exit(0);

	$res = lucc_msg("in_inbound_blacklist", array('unique_id' => $unique_id, 'number' => $caller_id));
	if(! $res or $res['response'] != 'ok')
		exit(0);

	$in = lucc_item($res, 'in');
	if($in != 'yes')
		exit(0);

	$agi->verbose("incoming call '$caller_id' in is blacklist!");

	$agi->set_variable('LUCC_RES', 'true');

?>
